#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

vector<set<int> > resources;
int n, m;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m;
	resources.resize(n);
	for (int i = 0; i < m; i++) {
		int t;
		cin >> t;
		for (int j = 0; j < t; j++) {
			int tmp;
			cin >> tmp;
			resources[tmp-1].insert(i);
		}
	}

	int ans = 1, rs_size = resources.size();
	sort(resources.begin(), resources.end());

	if (resources[0].empty()) ans = 0;
	for (int i = 1; i < rs_size; i++)
		if (resources[i] != resources[i-1]) {
			ans++;
			if (resources[i].empty()) ans--;
		}
	cout << ans << endl;
}
